<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/24
  Time: 11:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>产品登记模态框</title>
</head>
<body>
            <form id="produktionsregistrierungDispatchmodalfrom">
            <div class="modal-header">
                <input type="submit" class="btn btn-default" value="提交">
                <button class="close" data-dismiss="modal">退出</button>
            </div>
                <input type="hidden" name="parentId" id="produktionparentId">
                <input type="hidden" name="costPrice" id="produktioncostPrice">
                <input type="hidden" name="detailsNumber" id="index1">
            <div class="modal-body" align="center">
                <div class="row">
                    <div><strong><h2>生产登记单</h2></strong></div>
                </div>
                <input type="hidden" name="procedureId" id="procedureIdgx">
                <br>
                <div class="row">
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>派工单编号:</td>
                                <td><input type="text" id="produktondispatchmanufactureId" readonly style="outline: none;border: none;height: 40px"></td>
                            </tr>
                            <tr>
                                <td>负责人:</td>
                                <td><input type="text" readonly name="procedureResponsiblePerson" value="${username}" id="produktonprocedureResponsiblePerson"  style="outline: none;border: none;height: 40px;background-color: gainsboro"></td>
                            </tr>
                            <tr>
                                <td>已用工时:</td>
                                <td><input type="text" id="yjHourAmount"   readonly style="outline: none;border: none;height: 40px;"></td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>工序名称:</td>
                                <td><input type="text" name="procedureName" readonly id="priduktionproductName" style="outline: none;border: none;height: 40px"></td>
                            </tr>
                            <tr>
                                <td>设计工时:</td>
                                <td><input type="text" readonly id="labourHourlabourHourAmount" style="outline: none;border: none;height: 40px;"></td>
                            </tr>
                            <tr>
                                <td>本次工时:</td>
                                <td><input type="text" required name="labourHourAmount" id="producktinrealLabourHourAmount"   style="outline: none;border: none;height: 40px;background-color: gainsboro"></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <br>
            <div style="height:40%">
                    <table id="produktionsregistrierungDispatchmodaltab">

                    </table>
            </div>
            <br>
            <div class="row">
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>登记人:</td>
                                <td><input type="text" name="register" value="${username}" id="produktonregister" style="outline: none;border: none;height: 40px;background-color: gainsboro"></td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>登记时间:</td>
                                <td><input type="text" name="registerTime" id="produktonregisterTime" style="outline: none;border: none;height: 40px;"></td>
                            </tr>
                        </table>
                    </div>
            </div>
            </form>

            <script>
                //加载表格数据
                $(function () {
                    $("#produktionsregistrierungDispatchmodaltab").bootstrapTable({
                        contentType: "application/x-www-form-urlencoded", //如果用tomcat就要写这个
                        striped: true,//是否显示隔行变色
                        cache: false,//是否缓存
                        pagination: false,//是否显示分页
                        sortable: false,//是否显示排序
                        clickToSelect: true,//是否启用点击选中行
                        uniqueId:"id",//每一行的唯一标识，一般为主键列,
                        showRefresh: true,//是否显示刷新按钮
                        columns:[
                            {
                                field:"",
                                title:"序号",
                                formatter:function (value,row,index) {
                                    return Number(index)+1;
                                }
                            },
                            {
                                field:"productName",
                                title:"物料名称",
                            },
                            {
                                field:"productId",
                                title:"物料编号",
                            },
                            {
                                field:"amount",
                                title:"设计数量",
                            },
                            {
                                field:"realAmount",
                                title:"已经使用数量",
                            },
                            {
                                field:"isnum",
                                title:"本次数量",
                                formatter:function (value,row,index) {
                                    return "<input type='number' onchange='produktoonchange(this)' value='"+value+"' style='background-color: gainsboro'>"
                                }
                            }
                        ]
                    })
                })
                //根据当前工序编号查询物料
                //改变
                var f=true;
                function produktoonchange(num){
                    var ins=0;
                    //获取当前输入的值
                    var nums = $(num).val();
                    //当前编号
                    var ids=$(num).parent().parent().find("td").eq(2).text();
                    //获取表格数据
                    var produktion=$("#produktionsregistrierungDispatchmodaltab").bootstrapTable("getData")
                    //赋值
                    $(produktion).each(function (index,item) {
                        if(item.productId==ids){
                            item.isnum=nums;
                        }
                        if(Number(item.realAmount)+Number(item.isnum)>Number(item.amount)){
                            ins++;
                        }
                        if(Number(item.isnum)<0) {
                            ins++;
                        }
                    })
                    $("#produktionsregistrierungDispatchmodaltab").bootstrapTable("load",produktion)
                    if(ins!=0){
                        f=false;
                    }else {
                        f=true;
                    }
                }
                $(function () {
                    //获取id
                    var produktonid='${param.produktonid}'
                    var id='${param.id}'
                    var dispatchmanufactureId='${param.dispatchmanufactureId}'
                    var costPrice='${param.costPrice}'
                    var index1='${param.index1}'
                    $("#index1").val(index1)
                    $("#produktioncostPrice").val(costPrice)
                    $("#procedureIdgx").val(id)
                    $("#produktionparentId").val(produktonid)
                    //查询数据
                    $.post("queryByMProcedureModule.action",{"id":id},function (data) {
                        //赋值
                        //派工单编号
                        $("#produktondispatchmanufactureId").val(dispatchmanufactureId)
                        //已用工时
                        $("#yjHourAmount").val(0)
                        //负责人

                        //工序名称
                        $("#priduktionproductName").val(data.procedureName)
                        //设置工时
                        $("#labourHourlabourHourAmount").val(data.labourHourAmount)

                        //本次工时

                        //登记时间
                        //点击获取当前时间
                        $.get("queryCellByDate.action",function (data) {
                            $("#produktonregisterTime").val(data.datetime)
                        },"json")
                        //添加数据
                        var arr=[]
                        var datas=data.procedureModules;
                        for(var i=0;i<datas.length;i++){
                            arr.push(datas[i])
                        }
                        //加载表格数据
                        $("#produktionsregistrierungDispatchmodaltab").bootstrapTable("append",arr)
                    },"json")


                    $("#produktionsregistrierungDispatchmodalfrom").validate({
                        submitHandler:function () {
                            //获取form的数据
                            var arrs=$("#produktionsregistrierungDispatchmodalfrom").serializeArray();
                            var mProceduring={};
                            $(arrs).each(function (index,item) {
                                mProceduring[item.name]=item.value;
                            })
                            //获取表格数据
                            var arr=$("#produktionsregistrierungDispatchmodaltab").bootstrapTable("getData")
                            mProceduring["mproceduremodules"]=arr;
                            console.log(mProceduring)
                            if(f){
                                $.ajax({
                                    url:"addMproceduring.action",
                                    data:JSON.stringify(mProceduring),
                                    contentType:"application/json",
                                    type:"post",
                                    dataType:"json",
                                    success:function (data) {
                                        alert(data.msg)
                                        //关闭模态框
                                        $("#produktionsregistrierungDispatchmodal").modal("hide")
                                        //刷新表格
                                        alo()
                                    }
                                })
                            }else {
                                alert("数量输入有误")
                            }
                        }

                    })
                })


            </script>
</body>
</html>
